#include "Graph.h"

Vertex* Graph::AddVertex(Vector2 p)
{
	Vertex* v = new Vertex();
	v->data = p;
	Vertices.push_back(v);
	return v;
}

void Graph::Clear()
{
	for (std::vector<Vertex*>::iterator it = Vertices.begin(); it != Vertices.end(); ++it)
	{
		delete *it;
	}
	Vertices.clear();
}

void Vertex::Connect(Vertex* v)
{
	float a = (v->data.x - data.x);
	float b = (v->data.y - data.y);
	float d = sqrt(a * a + b * b);
	Edges.emplace_back();
	Edges.back().Origin = this;
	Edges.back().Destination = v;
	Edges.back().Distance = d;

	v->Edges.emplace_back();
	v->Edges.back().Origin = v;
	v->Edges.back().Destination = this;
	v->Edges.back().Distance = d;
}